package ex1;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Roi
 * Date: 10/18/13
 */
public class Ex1 {
    private static final String headers = "token        tag          line : column";

    public static void run(String[] args) {

        //  one parameter verifier
        if (args.length != 1)
            return;

        try {
            String line;
            String text = "";

            BufferedReader reader = new BufferedReader(new FileReader(args[0]));
            while ((line = reader.readLine()) != null) {
                text += line + "\n";
            }

            System.out.println(headers);

            ITokenizer tokenizer = new JflexTokenizer();
            List<Token> tokens = tokenizer.tokenize(text);

            for (Token tok : tokens) {
                //check for error
                if (tok instanceof TokenErr){
                    System.out.println(tok);
                    break;
                }
                System.out.println(tok);
            }

        } catch (Exception e) {
            System.err.println(e);
        }
    }
}
